#include <QCoreApplication>
#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>

#define MSGKEY 10241024

struct msgstru
{
   long msgtype;
   double x;
   double y;
   double rotate;
   double velocity;
};

/*子进程，监听消息队列*/
void childproc(){
  struct msgstru msgs;
  int msgid,ret_value;
  char str[512];

  while(1){
     msgid = msgget(MSGKEY,IPC_EXCL );/*检查消息队列是否存在 */
     if(msgid < 0){
        printf("msq not existed! errno=%d [%s]\n",errno,strerror(errno));
        sleep(2000);
        continue;
     }
     /*接收消息队列*/
     ret_value = msgrcv(msgid,&msgs,sizeof(struct msgstru),0,0);
     printf("x=[%lf],y=[%lf],rotate=[%lf], pid=[%d]\n",msgs.x,msgs.y,msgs.rotate,getpid());

  }
  return;
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);


    childproc();

    return a.exec();
}
